﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ReservoirBLL;
using ReservoirModel;

namespace ReservoirManger
{
    public partial class Reporting : System.Web.UI.Page
    {
        //定义为公共字段 供前台调用
        public string UserID;
        public string Name;
        protected void Page_Load(object sender, EventArgs e)
        {
            //读取用户资料
            TBUser users = IdentityManager.ReadUser();
            Name = users.Name;
            UserID = users.Id;
        }
        /// <summary>
        /// 提交数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            TBRecord record = new TBRecord();
            //从前台获取用户输入的值
            record.UserId = UserID;
            record.District = drProvince.SelectedValue + " " + drCity.SelectedValue;
            record.Name = txtName.Text;
            record.Area = Convert.ToDouble(txtArea.Text);
            record.Storage = Convert.ToDouble(txtStorage.Text);
            //遍历复选框中选中的值
            record.Functional = string.Empty;
            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (item.Selected == true)
                {
                    record.Functional += item.Value + " ";
                }
            }
            record.Maximum = Convert.ToDouble(txtMaximum.Text);
            record.WaterLevel = Convert.ToDouble(txtCurrent.Text);
            record.Remarks = txtReamrks.Text;

            //调用添加方法
            UserBLL userBLL = new UserBLL();
            int result = userBLL.AddInfo(record);
            if (result > 0)
            {
                Response.Write("<script>alert('添加成功！');window.location.href='Record.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('添加失败！')</script>");
            }
        }
    }
}
